import os
import sys
from loggingconf.log import logger


format_cmd = "ffmpeg -loop 0 -i %s/%s.jpg -vcodec libx264 -r 10  %s.mp4"
video_path = "/home/jack/Desktop/video/"
steal_path = video_path + "steal/"
not_steal_path = video_path+"notsteal/"

steal_index  = 0
not_steal_index = 0


def deal_data_path(data_path, steal):

    target_path = None
    items = os.listdir(data_path)
    for item in items:
        if steal:
            global steal_index
            target_path = steal_path + "steal%06d" % steal_index
            steal_index += 1
        else:
            global not_steal_index
            target_path = not_steal_path + "notsteal%06d" % not_steal_index
            not_steal_index += 1
        abs_item = os.path.join(data_path, item)+"/"
        logger.info(abs_item)
        cmd = format_cmd % (abs_item, "%06d", target_path)
        os.system(cmd)


def is_steal(src_path):
    steal_tail = src_path.split("/")[-1]
    steal = None
    if steal_tail[0] == 's':
        steal = True
    else:
        steal = False
    return steal


if __name__ == '__main__':
    os.mkdir(video_path)
    os.mkdir(steal_path)
    os.mkdir(not_steal_path)
    data_path = """/home/jack/Desktop/all_dust_thing/train_data/nosteal_cap1
    /home/jack/Desktop/all_dust_thing/train_data/nosteal_cap2
    /home/jack/Desktop/all_dust_thing/train_data/nosteal_cap3
    /home/jack/Desktop/all_dust_thing/train_data/steal_cap1
    /home/jack/Desktop/all_dust_thing/train_data/steal_cap2
    /home/jack/Desktop/all_dust_thing/train_data/steal_cap3"""
    data_path = data_path.split("\n")
    for path in data_path:
        path = path.strip()
        issteal = is_steal(path)
        deal_data_path(path, issteal)



